package com.wgts.wgts.mvp.presenter.imp;

import com.wgts.wgts.mvp.model.IAfterSaleActivityModel;
import com.wgts.wgts.mvp.presenter.IAfterSaleActivityPresenter;
import com.wgts.wgts.mvp.view.IAfterSaleActivityView;
import com.wgts.wgts.netmodle.HttpResultSubscriber;
import com.wgts.wgts.netmodle.req.IssurAfterSaleRequest;
import com.wgts.wgts.netmodle.resp.AfterSaleEntity;
import com.wgts.wgts.netmodle.resp.CurrentEntity;

import java.util.ArrayList;
import java.util.List;

/*
 *
 *   data:2018/10/1614:29
 *
 */public class AfterSaleActivityPresenter implements IAfterSaleActivityPresenter {
     private IAfterSaleActivityView view;
     private IAfterSaleActivityModel model;
     private List<AfterSaleEntity.Shop> shops;

    public AfterSaleActivityPresenter(IAfterSaleActivityView view, IAfterSaleActivityModel model) {
        this.view = view;
        this.model = model;
    }

    @Override
    public void initDate() {
        model.initDate(new HttpResultSubscriber<List<String>>() {
            @Override
            public void onSuccess(List<String> afterSaleEntity) {
                view.initDate(afterSaleEntity);
            }

            @Override
            public void _onError(int status, String msg) {

            }
        });
    }

    @Override
    public void initList(boolean isAll) {
        if (isAll){
            for (int i = 0; i < shops.size(); i++){
                shops.get(i).show = true;
                for (int j = 0; j < shops.get(i).products.size(); j++){
                    shops.get(i).products.get(j).show = true;
                }
            }
        }else {
            for (int i = 0; i < shops.size(); i++){
                shops.get(i).show = false;
                for (int j = 0; j < shops.get(i).products.size(); j++){
                    shops.get(i).products.get(j).show = false;
                }
            }
            shops.get(0).show = true;
            shops.get(0).products.get(0).show = true;
        }
        view.initList(shops);
    }

    @Override
    public void issueAfterSale(Integer orderId, String reason, String serviceType, String description, String images, String orderCode) {
        IssurAfterSaleRequest request = new IssurAfterSaleRequest();
        request.orderId = orderId;
        request.reason = reason;
        request.serviceType = serviceType;
        request.description = description;
        request.images  = images;
        request.orderCode = orderCode;
        model.issueAfterSale(request, new HttpResultSubscriber<CurrentEntity>() {
            @Override
            public void onSuccess(CurrentEntity currentEntity) {
                view.issueAfterSale();
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });
    }

}
